//
// Created by YueChuan on 2023/5/4.
//

#ifndef YUECHUAN_HTTP_SESSION_H
#define YUECHUAN_HTTP_SESSION_H

#include "socket_stream.h"
#include "http.h"
#include "http_parser.h"

namespace yuechuan {
    namespace http {
        class HttpSession : public SocketStream {
        public:
            typedef std::shared_ptr<HttpSession> ptr;

            /**
             * @brief 含参构造函数
             * @param sock Socket类型
             * @param owner 是否托管
             */
            HttpSession(Socket::ptr sock, bool owner = true);

            /**
             * @brief 接收Http请求
             * @return
             */
            HttpRequest::ptr recvRequest();

            /**
             * @brief 发送Http响应
             * @param rsp HTTP响应
             * @return > 0 成功发送
             *          = 0 对方关闭
             *          < 0 Socket异常
             */
            int sendResponse(HttpResponse::ptr rsp);
        };
    }

}


#endif //YUECHUAN_HTTP_SESSION_H
